package com.ruoyi.web.controller.fantasy;

import java.util.List;

import com.ruoyi.common.utils.IdWorker;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.huanzhidadi.fantasy.bean.domain.FantasyTitlePropertyRequirement;
import com.ruoyi.fantasy.service.IFantasyTitlePropertyRequirementService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 称号属性要求Controller
 * 
 * @author wanghui
 * @date 2020-04-11
 */
@Controller
@RequestMapping("/fantasy/fantasyTitleRequirement")
public class FantasyTitlePropertyRequirementController extends BaseController
{
    private String prefix = "fantasy/fantasyTitleRequirement";

    @Autowired
    private IFantasyTitlePropertyRequirementService fantasyTitlePropertyRequirementService;

    @RequiresPermissions("fantasy:requirement:view")
    @GetMapping()
    public String requirement()
    {
        return prefix + "/requirement";
    }

    /**
     * 查询称号属性要求列表
     */
    @RequiresPermissions("fantasy:requirement:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FantasyTitlePropertyRequirement fantasyTitlePropertyRequirement)
    {
        startPage();
        List<FantasyTitlePropertyRequirement> list = fantasyTitlePropertyRequirementService.selectFantasyTitlePropertyRequirementList(fantasyTitlePropertyRequirement);
        fantasyTitlePropertyRequirementService.transforData(list);
        return getDataTable(list);
    }

    /**
     * 导出称号属性要求列表
     */
    @RequiresPermissions("fantasy:requirement:export")
    @Log(title = "称号属性要求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FantasyTitlePropertyRequirement fantasyTitlePropertyRequirement)
    {
        List<FantasyTitlePropertyRequirement> list = fantasyTitlePropertyRequirementService.selectFantasyTitlePropertyRequirementList(fantasyTitlePropertyRequirement);
        ExcelUtil<FantasyTitlePropertyRequirement> util = new ExcelUtil<FantasyTitlePropertyRequirement>(FantasyTitlePropertyRequirement.class);
        return util.exportExcel(list, "requirement");
    }

    /**
     * 新增称号属性要求
     */
    @GetMapping("/add/{titleId}")
    public String add(@PathVariable("titleId") String titleId, ModelMap mmap)
    {
        mmap.put("titleId", titleId);
        return prefix + "/add";
    }

    /**
     * 新增保存称号属性要求
     */
    @RequiresPermissions("fantasy:requirement:add")
    @Log(title = "称号属性要求", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FantasyTitlePropertyRequirement fantasyTitlePropertyRequirement)
    {
        // 取身份信息
        SysUser user = ShiroUtils.getSysUser();
        fantasyTitlePropertyRequirement.setId(String.valueOf(IdWorker.nextId()));
        fantasyTitlePropertyRequirement.setCreateBy(user.getUserId().toString());
        return toAjax(fantasyTitlePropertyRequirementService.insertFantasyTitlePropertyRequirement(fantasyTitlePropertyRequirement));
    }

    /**
     * 修改称号属性要求
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        FantasyTitlePropertyRequirement fantasyTitlePropertyRequirement = fantasyTitlePropertyRequirementService.selectFantasyTitlePropertyRequirementById(id);
        mmap.put("fantasyTitlePropertyRequirement", fantasyTitlePropertyRequirement);
        return prefix + "/edit";
    }

    /**
     * 修改保存称号属性要求
     */
    @RequiresPermissions("fantasy:requirement:edit")
    @Log(title = "称号属性要求", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FantasyTitlePropertyRequirement fantasyTitlePropertyRequirement)
    {
        // 取身份信息
        SysUser user = ShiroUtils.getSysUser();
        fantasyTitlePropertyRequirement.setUpdateBy(user.getUserId().toString());
        return toAjax(fantasyTitlePropertyRequirementService.updateFantasyTitlePropertyRequirement(fantasyTitlePropertyRequirement));
    }

    /**
     * 删除称号属性要求
     */
    @RequiresPermissions("fantasy:requirement:remove")
    @Log(title = "称号属性要求", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fantasyTitlePropertyRequirementService.deleteFantasyTitlePropertyRequirementByIds(ids));
    }
}
